         SOURCE CODE LISTING FOR X10-ADAM HOME AUTOMATION CONTROLLER

   *All memory location related to SmartBASIC in decimal
0000-00          0001           ORG      29000
   *Initial serial port to 600bps,8,1,N
0000-00  DB47    0002  Serinit  IN       A,(47h)         ;Reset 2651
0002-00  3E6E    0003           LD       A,6Eh           ;8,1,N
0004-00  D346    0004           OUT      (46h),A
0006-00  3E36    0005           LD       A,36h           ;600bps         internal clock
0008-00  D346    0006           OUT      (46h),A
000A-00  3E07    0007           LD       A,7h            ;tx,rx enable
000C-00  D347    0008           OUT      (47h),A
000E-00  DB44    0009           IN       A,(44h)         ;Clear rev
0010-00  DB44    0010           IN       A,(44h)         ;one more
0012-00  C9      0011           RET
   *Data upload from controller, number of byte to get is in location    29025
0013-00  21AC71  0012  Dupload  LD       HL,29100        ;Memory addrs
0016-00  0E44    0013           LD       C,(44h)
0018-00  060D    0014           LD       B,0Dh           ;Number of byte to get
001A-00  DB45    0015  loop1    IN       A,(45h)         ;read status
001C-00  E602    0016           AND      02h             ;get D1
001E-00  28FA    0017           JR       Z,loop1
0020-00  EDA2    0018           INI                      ;save data
0022-00  20F6    0019           JR       NZ,loop1        ;get next data
0024-00  C9      0020           RET
   *Output single byte in location 29044 to controller
0025-00  DB45    0021  serout   IN       A,(45h)         ;get status
0027-00  E601    0022           AND      01h             ;get D0
0029-00  28FA    0023           JR       Z,serout
002B-00  3E00    0024           LD       A,0h            ;data to send
002D-00  D344    0025           OUT      (44h),A         ;send it out
002F-00  C9      0026           RET
   *Get a single byte from serial interface
0030-00  06FE    0027  serin    LD       B,0FEh
0032-00  05      0028  sinput   DEC      B
0033-00  280D    0029           JR       Z,sererr
0035-00  DB45    0030           IN       A,(45h)
0037-00  E602    0031           AND      02h             ;get D1
0039-00  28F7    0032           JR       Z,sinput
003B-00  21AC71  0033           LD       HL,29100        ;memory         location
003E-00  DB44    0034           IN       A,(44h)
0040-00  77      0035           LD       (HL),A          ;save data
0041-00  C9      0036           RET
   *Use this to avoid hang-up when RS-232 serial interface not active
0042-00  21CA71  0037  sererr   LD       HL,29130
0045-00  3E00    0038           LD       A,0h
0047-00  77      0039           LD       (HL),A          ;indicated      error occur
0048-00  C9      0040           RET
   *Calculate checksum start  at location 29150 of that many byte in     Reg.B
0049-00  3E00    0041           LD       A,0h
004B-00  0604    0042           LD       B,4             ;do for this    many byte
004D-00  21DE71  0043           LD       HL,29150        ;start here
0050-00  86      0044  csum     ADD      A,(HL)
0051-00  23      0045           INC      HL
0052-00  05      0046           DEC      B
0053-00  20FB    0047           JR       NZ,csum
0055-00  77      0048           LD       (HL),A          ;store result   here
0056-00  C9      0049           RET
                 0050           END
.. ...-....                                                             0041-00  C9      0036           RET
   *Use this to avoid hang-up when RS-232 serial inter